# -*- coding: utf-8 -*-
"""
Created on 2024-09-14 14:39:20
---------
@summary:
---------
@author: Administrator
"""
import uuid
import feapder
from feapder.db.redisdb import RedisDB
from feapder.db.mysqldb import MysqlDB
class BaseInfo(feapder.TaskSpider):
    db_name = "qierge_32"
    _rdc = None
    _db = None
    # 自定义数据库，若项目中有setting.py文件，此自定义可删除
    __custom_setting__ = dict(
        REDISDB_IP_PORTS="localhost:6379",
        # REDISDB_IP_PORTS = "139.9.196.26:6379"
        REDISDB_USER_PASS=''"python",
        REDISDB_DB=9,
        MYSQL_IP="rm-bp152ng910khxljk85o.mysql.rds.aliyuncs.com",
        MYSQL_PORT=3306,
        MYSQL_DB=db_name,
        MYSQL_USER_NAME="dev",
        MYSQL_USER_PASS="3NG1LRYKCVKa8dQZ+HkpcQ",
        LOG_LEVEL="INFO"
    )
    @property
    def db(self):
        if not self._db:
            self._db = MysqlDB()
        return self._db
    @property
    def rdc(self):
        if not self._rdc:
            self._rdc = RedisDB()
        return self._rdc
    @property
    def get_digest(self):
        return uuid.uuid4().hex.upper()

    def start_requests(self, task):
        id = task.id
        digest=task.digest
        name=task.name
        creditCode=task.creditCode
        regNumber=task.regNumber
        city=task.city
        district=task.district
        provinceId=task.provinceId
        data={

        }

        headers={

        }
        yield feapder.Request("https://www.qcc.com/api/search/searchMind",data=data,headers=headers)
    def parse(self, request, response):
        yield self.update_task_batch(request.task_id)


if __name__ == "__main__":
    # 用mysql做任务表，需要先建好任务任务表
    spider = BaseInfo(
        redis_key="qcc:baseinfo",  # 分布式爬虫调度信息存储位置
        task_table="py_company_base",  # mysql中的任务表
        task_keys=["id", "digest","name",'creditCode','regNumber',"city","district","provinceId"],  # 需要获取任务表里的字段名，可添加多个
        task_state="reportState",  # mysql中任务状态字段
    )
    spider.add_task()
    spider.start()